Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Encapsulation (computer programming)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Encapsulation_computer_programming rootpage-Encapsulation_computer_programming skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Encapsulation (computer programming)</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1236090951">
/* start https://en.wikipedia.org/ */


.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}


/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable">For other uses, see <a href="Encapsulation_(disambiguation)" class="mw-redirect mw-disambig" title="Encapsulation (disambiguation)">Encapsulation</a>.</div>
<p>In software systems, <b>encapsulation</b> refers to the bundling of data with the mechanisms or methods that operate on the data. It may also refer to the limiting of direct access to some of that data, such as an object's components.<sup id="cite_ref-Rogers01_1-0" class="reference"><a href="#cite_note-Rogers01-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> Essentially, encapsulation prevents external code from being concerned with the internal workings of an object.
</p><p>Encapsulation allows developers to present a consistent interface that is independent of its internal implementation. As one example, encapsulation can be used to hide the values or state of a structured data object inside a <a href="Class_(computer_programming)" title="Class (computer programming)">class</a>. This prevents clients from directly accessing this information in a way that could expose hidden implementation details or violate <a href="State_(computer_science)" title="State (computer science)">state</a> invariance maintained by the methods.
</p><p>Encapsulation also encourages programmers to put all the code that is concerned with a certain set of data in the same class, which organizes it for easy comprehension by other programmers. Encapsulation is a technique that encourages <a href="Coupling_(computer_programming)" title="Coupling (computer programming)">decoupling</a>.
</p><p>All <a href="Object-oriented_programming" title="Object-oriented programming">object-oriented programming</a> (OOP) systems support encapsulation,<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> but encapsulation is not unique to OOP. Implementations of <a href="Abstract_data_types" class="mw-redirect" title="Abstract data types">abstract data types</a>, <a href="Module_(programming)" class="mw-redirect" title="Module (programming)">modules</a>, and <a href="Library_(computing)" title="Library (computing)">libraries</a> also offer encapsulation. The similarity has been explained by programming language theorists in terms of <a href="Existential_types" class="mw-redirect" title="Existential types">existential types</a>.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup>
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Meaning">Meaning</h2></div>
<p>In <a href="Object-oriented_programming_languages" class="mw-redirect" title="Object-oriented programming languages">object-oriented programming languages</a>, and other related fields, encapsulation refers to one of two related but distinct notions, and sometimes to the combination thereof:<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-Dale_6-0" class="reference"><a href="#cite_note-Dale-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup>
</p>
<ul><li>A language mechanism for restricting direct access to some of the <a href="Object_(computer_science)" title="Object (computer science)">object</a>'s components.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-Pierce_8-0" class="reference"><a href="#cite_note-Pierce-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup></li>
<li>A language construct that facilitates the bundling of data with the <a href="Method_(computer_programming)" title="Method (computer programming)">methods</a> (or other functions) operating on those data.<sup id="cite_ref-Rogers01_1-1" class="reference"><a href="#cite_note-Rogers01-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-9" class="reference"><a href="#cite_note-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup></li></ul>
<p>Some programming language researchers and academics use the first meaning alone or in combination with the second as a distinguishing feature of <a href="Object-oriented_programming" title="Object-oriented programming">object-oriented programming</a>, while some programming languages that provide <a href="Closure_(computer_programming)" title="Closure (computer programming)">lexical closures</a> view encapsulation as a feature of the language <a href="Orthogonality#Computer_science" title="Orthogonality">orthogonal</a> to object orientation.
</p><p>The second definition reflects that in many object-oriented languages, and other related fields, the components are not hidden automatically and this can be overridden. Thus, <a href="Information_hiding" title="Information hiding">information hiding</a> is defined as a separate notion by those who prefer the second definition.
</p><p>The features of encapsulation are supported using <a href="Class_(computer_programming)" title="Class (computer programming)">classes</a> in most object-oriented languages, although other alternatives also exist.
</p><p>Encapsulation may also refer to containing a repetitive or complex process in a single unit to be invoked. Object-oriented programming facilitate this at both the method and class levels. This definition is also applicable to <a href="Procedural_programming" title="Procedural programming">procedural programming</a>.<sup id="cite_ref-10" class="reference"><a href="#cite_note-10"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading3"><h3 id="Encapsulation_and_inheritance">Encapsulation and inheritance</h3></div>
<p>The authors of <i><a href="Design_Patterns" title="Design Patterns">Design Patterns</a></i> discuss the tension between <a href="Inheritance_(object-oriented_programming)" title="Inheritance (object-oriented programming)">inheritance</a> and encapsulation at length and state that in their experience, designers overuse inheritance. They claim that inheritance often breaks encapsulation, given that inheritance exposes a subclass to the details of its parent's implementation.<sup id="cite_ref-GoF_11-0" class="reference"><a href="#cite_note-GoF-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup> As described by the <a href="Yo-yo_problem" title="Yo-yo problem">yo-yo problem</a>, overuse of inheritance and therefore encapsulation, can become too complicated and hard to debug.
</p>
<div class="mw-heading mw-heading2"><h2 id="Information_hiding">Information hiding</h2></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Information_hiding" title="Information hiding">Information hiding</a></div>
<p>Under the definition that encapsulation "can be used to hide data members and member functions", the internal representation of an <a href="Object_(computer_science)" title="Object (computer science)">object</a> is generally hidden outside of the object's definition. Typically, only the object's own methods can directly inspect or manipulate its fields. Hiding the internals of the object protects its integrity by preventing users from setting the internal data of the component into an invalid or inconsistent state. A supposed benefit of encapsulation is that it can reduce system complexity, and thus increase <a href="Robustness_(computer_science)" title="Robustness (computer science)">robustness</a>, by allowing the developer to limit the interdependencies between software components.
</p><p>Some languages like <a href="Smalltalk" title="Smalltalk">Smalltalk</a> and <a href="Ruby_(programming_language)" title="Ruby (programming language)">Ruby</a> only allow access via object methods, but most others (e.g., <a href="C%2B%2B" title="C++">C++</a>, <a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a>, <a href="Delphi_(programming_language)" class="mw-redirect" title="Delphi (programming language)">Delphi</a> or <a href="Java_(programming_language)" title="Java (programming language)">Java</a><sup id="cite_ref-FOOTNOTEBloch201873–77Chapter_§4_Item_15_Minimize_the_accessibility_of_classes_and_members_12-0" class="reference"><a href="#cite_note-FOOTNOTEBloch201873–77Chapter_§4_Item_15_Minimize_the_accessibility_of_classes_and_members-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup>) offer the programmer some control over what is hidden, typically via keywords like <code>public</code> and <code>private</code>.<sup id="cite_ref-Pierce_8-1" class="reference"><a href="#cite_note-Pierce-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup> ISO C++ standard refers to <code>protected</code>, <code>private</code> and <code>public</code> as "<a href="Access_specifiers" class="mw-redirect" title="Access specifiers">access specifiers</a>" and that they do not "hide any information". Information hiding is accomplished by furnishing a compiled version of the source code that is interfaced via a header file.
</p><p>Almost always, there is a way to override such protection – usually via <a href="Reflection_(computer_programming)" class="mw-redirect" title="Reflection (computer programming)">reflection</a> API (Ruby, Java, C#, etc.), sometimes by mechanism like <a href="Name_mangling" title="Name mangling">name mangling</a> (<a href="Python_(programming_language)" title="Python (programming language)">Python</a>), or special keyword usage like <code>friend</code> in C++. Systems that provide object-level <a href="Capability-based_security" title="Capability-based security">capability-based security</a> (adhering to the <a href="Object-capability_model" title="Object-capability model">object-capability model</a>) are an exception, and guarantee strong encapsulation.
</p>
<div class="mw-heading mw-heading3"><h3 id="Examples">Examples</h3></div>
<div class="mw-heading mw-heading4"><h4 id="Restricting_data_fields">Restricting data fields</h4></div>
<p>Languages like <a href="C%2B%2B" title="C++">C++</a>, <a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a>, <a href="Java_(programming_language)" title="Java (programming language)">Java</a>,<sup id="cite_ref-FOOTNOTEBloch201873–77Chapter_§4_Item_15_Minimize_the_accessibility_of_classes_and_members_12-1" class="reference"><a href="#cite_note-FOOTNOTEBloch201873–77Chapter_§4_Item_15_Minimize_the_accessibility_of_classes_and_members-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup> <a href="PHP" title="PHP">PHP</a>, <a href="Swift_(programming_language)" title="Swift (programming language)">Swift</a>, and <a href="Delphi_(programming_language)" class="mw-redirect" title="Delphi (programming language)">Delphi</a> offer ways to restrict access to data fields.
</p><p><span class="mw-default-size" typeof="mw:File"></span>
</p><p>Below is an example in <a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a> that shows how access to a data field can be restricted through the use of a <code>private</code> keyword:
</p>
<div class="mw-highlight mw-highlight-lang-csharp mw-content-ltr" dir="ltr"><pre><span class="k">class</span><span class="w"> </span><span class="nc">Program</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="k">class</span><span class="w"> </span><span class="nc">Account</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">private</span><span class="w"> </span><span class="kt">decimal</span><span class="w"> </span><span class="n">_accountBalance</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mf">500.00m</span><span class="p">;</span>

<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="kt">decimal</span><span class="w"> </span><span class="nf">CheckBalance</span><span class="p">()</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">_accountBalance</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="k">void</span><span class="w"> </span><span class="nf">Main</span><span class="p">()</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Account</span><span class="w"> </span><span class="n">myAccount</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Account</span><span class="p">();</span>
<span class="w"> </span><span class="kt">decimal</span><span class="w"> </span><span class="n">myBalance</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">myAccount</span><span class="p">.</span><span class="n">CheckBalance</span><span class="p">();</span>

<span class="w"> </span><span class="cm">/* This Main method can check the balance via the public</span>
<span class="cm"> * "CheckBalance" method provided by the "Account" class </span>
<span class="cm"> * but it cannot manipulate the value of "accountBalance" */</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
</pre></div>
<p>Below is an example in <a href="Java_(programming_language)" title="Java (programming language)">Java</a>:
</p>
<div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Employee</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kd">private</span><span class="w"> </span><span class="n">BigDecimal</span><span class="w"> </span><span class="n">salary</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">BigDecimal</span><span class="p">(</span><span class="mf">50000.00</span><span class="p">);</span>
<span class="w"> </span>
<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="n">BigDecimal</span><span class="w"> </span><span class="nf">getSalary</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">salary</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Employee</span><span class="w"> </span><span class="n">e</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Employee</span><span class="p">();</span>
<span class="w"> </span><span class="n">BigDecimal</span><span class="w"> </span><span class="n">sal</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">e</span><span class="p">.</span><span class="na">getSalary</span><span class="p">();</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
</pre></div>
<p>Encapsulation is also possible in non-object-oriented languages. In <a href="C_(programming_language)" title="C (programming language)">C</a>, for example, a structure can be declared in the public API via the header file for a set of functions that operate on an item of data containing data members that are not accessible to clients of the API with the <code>extern</code> keyword.<sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="c1">// Header file "api.h"</span>

<span class="k">struct</span><span class="w"> </span><span class="nc">Entity</span><span class="p">;</span><span class="w"> </span><span class="c1">// Opaque structure with hidden members</span>

<span class="c1">// API functions that operate on 'Entity' objects</span>
<span class="k">extern</span><span class="w"> </span><span class="k">struct</span><span class="w"> </span><span class="nc">Entity</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">open_entity</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">id</span><span class="p">);</span>
<span class="k">extern</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">process_entity</span><span class="p">(</span><span class="k">struct</span><span class="w"> </span><span class="nc">Entity</span><span class="w"> </span><span class="o">*</span><span class="n">info</span><span class="p">);</span>
<span class="k">extern</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">close_entity</span><span class="p">(</span><span class="k">struct</span><span class="w"> </span><span class="nc">Entity</span><span class="w"> </span><span class="o">*</span><span class="n">info</span><span class="p">);</span>
<span class="c1">// extern keywords here are redundant, but don't hurt.</span>
<span class="c1">// extern defines functions that can be called outside the current file, the default behavior even without the keyword</span>
</pre></div>
<p>Clients call the API functions to allocate, operate on, and deallocate objects of an <a href="Opaque_data_type" title="Opaque data type">opaque data type</a>. The contents of this type are known and accessible only to the implementation of the API functions; clients cannot directly access its contents. The source code for these functions defines the actual contents of the structure:
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="c1">// Implementation file "api.c"</span>

<span class="cp">#include</span><span class="w"> </span><span class="cpf">"api.h"</span>

<span class="k">struct</span><span class="w"> </span><span class="nc">Entity</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">ent_id</span><span class="p">;</span><span class="w"> </span><span class="c1">// ID number</span>
<span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="n">ent_name</span><span class="p">[</span><span class="mi">20</span><span class="p">];</span><span class="w"> </span><span class="c1">// Name</span>
<span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="n">and</span><span class="w"> </span><span class="n">other</span><span class="w"> </span><span class="n">members</span><span class="w"> </span><span class="p">...</span>
<span class="p">};</span>

<span class="c1">// API function implementations</span>
<span class="k">struct</span><span class="w"> </span><span class="nc">Entity</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">open_entity</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">id</span><span class="p">)</span>
<span class="p">{</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">}</span>

<span class="kt">int</span><span class="w"> </span><span class="n">process_entity</span><span class="p">(</span><span class="k">struct</span><span class="w"> </span><span class="nc">Entity</span><span class="w"> </span><span class="o">*</span><span class="n">info</span><span class="p">)</span>
<span class="p">{</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">}</span>

<span class="kt">void</span><span class="w"> </span><span class="n">close_entity</span><span class="p">(</span><span class="k">struct</span><span class="w"> </span><span class="nc">Entity</span><span class="w"> </span><span class="o">*</span><span class="n">info</span><span class="p">)</span>
<span class="p">{</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">}</span>
</pre></div>
<div class="mw-heading mw-heading4"><h4 id="Name_mangling">Name mangling</h4></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Name_mangling" title="Name mangling">Name mangling</a></div>
<p>Below is an example of <a href="Python_(programming_language)" title="Python (programming language)">Python</a>, which does not support variable access restrictions. However, the convention is that a variable whose name is prefixed by an underscore should be considered private.<sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-python mw-content-ltr" dir="ltr"><pre><span class="k">class</span><span class="w"> </span><span class="nc">Car</span><span class="p">:</span>
<span class="k">def</span><span class="w"> </span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_maxspeed</span> <span class="o">=</span> <span class="mi">200</span>
<span class="k">def</span><span class="w"> </span><span class="nf">drive</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"Maximum speed is </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_maxspeed</span><span class="si">}</span><span class="s2">."</span><span class="p">)</span>
<span class="n">redcar</span> <span class="o">=</span> <span class="n">Car</span><span class="p">()</span>
<span class="n">redcar</span><span class="o">.</span><span class="n">drive</span><span class="p">()</span> <span class="c1"># This will print 'Maximum speed is 200.'</span>

<span class="n">redcar</span><span class="o">.</span><span class="n">_maxspeed</span> <span class="o">=</span> <span class="mi">10</span>
<span class="n">redcar</span><span class="o">.</span><span class="n">drive</span><span class="p">()</span> <span class="c1"># This will print 'Maximum speed is 10.'</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Inheritance_(object-oriented_programming)" title="Inheritance (object-oriented programming)">Inheritance (object-oriented programming)</a></li>
<li><a href="Object-oriented_programming" title="Object-oriented programming">Object-oriented programming</a></li>
<li><a href="Software_design_pattern" title="Software design pattern">Software design pattern</a></li>
<li><a href="Facade_pattern" title="Facade pattern">Facade pattern</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="Citations">Citations</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */


.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}


/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap mw-references-columns"><ol class="references">
<li id="cite_note-Rogers01-1"><span class="mw-cite-backlink">^ <a href="#cite_ref-Rogers01_1-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Rogers01_1-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFRogers2001" class="citation web cs1">Rogers, Wm. Paul (18 May 2001). <a rel="nofollow" class="external text" href="https://www.infoworld.com/article/2075271/encapsulation-is-not-information-hiding.html">"Encapsulation is not information hiding"</a>. <i><a href="JavaWorld" class="mw-redirect" title="JavaWorld">JavaWorld</a></i><span class="reference-accessdate">. Retrieved <span class="nowrap">2020-07-20</span></span>.</cite></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.techtarget.com/searchapparchitecture/definition/object-oriented-programming-OOP">"What is Object-Oriented Programming (OOP)?"</a>. <i>App Architecture</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2024-03-02</span></span>.</cite></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.enjoyalgorithms.com/blog/encapsulation-in-oops/">"Encapsulation in Object Oriented Programming (OOPS)"</a>. <i>www.enjoyalgorithms.com</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2024-03-02</span></span>.</cite></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><a href="#CITEREFPierce2002">Pierce 2002</a>, § 24.2 Data Abstraction with Existentials</span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><cite id="CITEREFScott2006" class="citation book cs1">Scott, Michael Lee (2006). <i>Programming language pragmatics</i> (2&nbsp;ed.). Morgan Kaufmann. p.&nbsp;481. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-12-633951-2</bdi>. <q>Encapsulation mechanisms enable the programmer to group data and the subroutines that operate on them together in one place, and to hide irrelevant details from the users of an abstraction</q></cite></span>
</li>
<li id="cite_note-Dale-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-Dale_6-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFDaleWeems2007" class="citation book cs1">Dale, Nell B.; Weems, Chip (2007). <i>Programming and problem solving with Java</i> (2nd&nbsp;ed.). Jones &amp; Bartlett. p.&nbsp;396. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-7637-3402-2</bdi>.</cite></span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><cite id="CITEREFMitchell2003" class="citation book cs1"><a href="John_C._Mitchell" title="John C. Mitchell">Mitchell, John C.</a> (2003). <i>Concepts in programming languages</i>. Cambridge University Press. p.&nbsp;522. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-521-78098-8</bdi>.</cite></span>
</li>
<li id="cite_note-Pierce-8"><span class="mw-cite-backlink">^ <a href="#cite_ref-Pierce_8-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Pierce_8-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFPierce2002" class="citation book cs1"><a href="Benjamin_C._Pierce" title="Benjamin C. Pierce">Pierce, Benjamin</a> (2002). <a href="Types_and_Programming_Languages" title="Types and Programming Languages"><i>Types and Programming Languages</i></a>. MIT Press. p.&nbsp;266. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-262-16209-8</bdi>.</cite></span>
</li>
<li id="cite_note-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-9">^</a></b></span> <span class="reference-text"><cite id="CITEREFConnollyBegg2005" class="citation book cs1">Connolly, Thomas M.; Begg, Carolyn E. (2005). "Ch. 25: Introduction to Object DMBS § Object-oriented concepts". <i>Database systems: a practical approach to design, implementation, and management</i> (4th&nbsp;ed.). Pearson Education. p.&nbsp;814. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-321-21025-8</bdi>.</cite></span>
</li>
<li id="cite_note-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-10">^</a></b></span> <span class="reference-text"><cite id="CITEREFMcDonough2017" class="citation book cs1">McDonough, James E. (2017). "Encapsulation". <i>Object-Oriented Design with ABAP: A Practical Approach</i>. <a href="Apress" class="mw-redirect" title="Apress">Apress</a>. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1007%2F978-1-4842-2838-8">10.1007/978-1-4842-2838-8</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-1-4842-2837-1</bdi> – via <a href="O'Reilly_Media" title="O'Reilly Media">O'Reilly</a>.</cite></span>
</li>
<li id="cite_note-GoF-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-GoF_11-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFGammaHelmJohnsonVlissides1994" class="citation book cs1">Gamma, Erich; Helm, Richard; Johnson, Ralph; Vlissides, John (1994). <span class="id-lock-registration" title="Free registration required"><a rel="nofollow" class="external text" href="https://archive.org/details/designpatternsel00gamm"><i>Design Patterns</i></a></span>. Addison-Wesley. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0-201-63361-0</bdi>.</cite></span>
</li>
<li id="cite_note-FOOTNOTEBloch201873–77Chapter_§4_Item_15_Minimize_the_accessibility_of_classes_and_members-12"><span class="mw-cite-backlink">^ <a href="#cite_ref-FOOTNOTEBloch201873–77Chapter_§4_Item_15_Minimize_the_accessibility_of_classes_and_members_12-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-FOOTNOTEBloch201873–77Chapter_§4_Item_15_Minimize_the_accessibility_of_classes_and_members_12-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><a href="#CITEREFBloch2018">Bloch 2018</a>, pp.&nbsp;73–77, Chapter §4 Item 15 Minimize the accessibility of classes and members.</span>
</li>
<li id="cite_note-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-13">^</a></b></span> <span class="reference-text"><cite id="CITEREFKing2008" class="citation book cs1">King, K. N. (2008). <i>C Programming: A Modern Approach</i> (2nd&nbsp;ed.). W. W. Norton &amp; Company. p.&nbsp;464. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0393979503</bdi>.</cite></span>
</li>
<li id="cite_note-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-14">^</a></b></span> <span class="reference-text"><cite id="CITEREFBader" class="citation web cs1">Bader, Dan. <a rel="nofollow" class="external text" href="https://dbader.org/blog/meaning-of-underscores-in-python">"The Meaning of Underscores in Python"</a>. <i>Improve Your Python Skills</i><span class="reference-accessdate">. Retrieved <span class="nowrap">1 November</span> 2019</span>.</cite></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<ul><li><cite id="CITEREFBloch2018" class="citation book cs1">Bloch, Joshua (2018). <i>"Effective Java: Programming Language Guide"</i> (third&nbsp;ed.). Addison-Wesley. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0134685991</bdi>.</cite></li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-06-16" href="https://en.wikipedia.org/wiki/?title=Encapsulation_(computer_programming)&amp;oldid=1295814643">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>